package com.peaksport.framework.metadata.selector;

import java.io.Serializable;

import com.peaksport.framework.map.ListMap;
import com.peaksport.framework.util.PKPublicUtils;

/**
 * 
 * 
 * @author jinbin_guo  2019年4月15日 下午4:52:28
 *
 */

@SuppressWarnings("serial")
public class SelectorItemCollection implements Serializable {

    private ListMap<SelectorItemInfo> col = new ListMap<>();

    public ListMap<SelectorItemInfo> getCollection() {
        return col;
    }

    public void setCollection(ListMap<SelectorItemInfo> col) {
        this.col = col;
    }
    public void addCollection(SelectorItemCollection newCol) {
        if (newCol == null || newCol.isEmpty()) return;
        for (int i = 0, len = newCol.size(); i < len; i++) {
            SelectorItemInfo selectorItemInfo = newCol.get(i);
            addSelectorItemInfo(selectorItemInfo);
        }
    }

    public void addSelectorItemInfo(SelectorItemInfo selectorItemInfo) {
        col.add(selectorItemInfo.getPropertyName(),selectorItemInfo);
    }

    public SelectorItemInfo get(int index) {
        return col.get(index);
    }

    public SelectorItemInfo get(String key) {
        return  col.get(key);
    }
    public int size() {
        return col.size();
    }

    public boolean isEmpty() {
        return size() == 0;
    }

    public String toSQL() {
        StringBuilder sql = new StringBuilder();
        for (int i = 0, len = col.size(); i < len; i++) {
            SelectorItemInfo selectorItemInfo = col.get(i);
            sql.append(selectorItemInfo.toSQL()) ;
            if (i != len -1) sql.append(",");
        }

        return  sql.toString();
    }

    @Override
    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append("[");
        for (int i = 0,len = col.size(); i < len; i++) {
            SelectorItemInfo selectorItemInfo = col.get(i);
            str.append(selectorItemInfo.toString());
            if (i != len - 1) str.append(",").append(PKPublicUtils.CR);

        }
        str.append("]");
        return str.toString();

    }
}
